package jn.chen.utils.emailCode.controller;

import jn.chen.utils.emailCode.dto.EmailDTO;
import jn.chen.utils.emailCode.service.SendEmail;
import jn.chen.utils.emailCode.utils.AjaxResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.mail.MessagingException;

/**
 * @className: SendEmailController
 * @author: chenLin
 * @version: 1.0.0
 * @description:
 * @date: 2022/11/1 0001 14:42
 */
@RestController
@RequestMapping("/email")
public class SendEmailController {

    @Resource
    private SendEmail sendEmail;

    /**
     * 发送邮件
     *  email 收件人信息
     *  结果
     */
    @PostMapping("/sendEmail")
    public AjaxResult sendEmail( EmailDTO email) {

        String sendHtmlBool;
        try {
            sendHtmlBool = sendEmail.sendHtmlEmail(email);
        } catch (MessagingException e) {
            throw new RuntimeException("邮件发送失败！");
        }
        return AjaxResult.success(sendHtmlBool);
    }

}
